<template>
    <div class="template-index-Lu">
        <commpVxeTable
            :key="reCommpVxeTable"
            :config="dataConfig()"
            :columns="columns()"
            :formItem="item()"
            @checkboxChange="checkboxChange"
            ref="administrativeOffice"
            @searchEvent="searchEvent"
            @resetEvent="resetEvent"
            >
            <template v-slot:ksTime_slot>
                <a-date-picker
                :show-time="{ defaultValue: moment('00:00', 'HH:mm') }"
                format="YYYY-MM-DD HH:mm"
                v-model="fhykssj"
                @change="onChange1"/>
            </template>
            <template v-slot:jsTime_slot>
                <a-date-picker
                :show-time="{ defaultValue: moment('59:59', 'HH:mm') }"
                format="YYYY-MM-DD HH:mm"
                v-model="fhyjssj"
                @change="onChange2"/>
            </template>
            <template v-slot:operation_btn="{row}" data-desc="自定操作栏">
                <a-form layout="inline">
                    <a-form-item>
                        <a-button class="blue-btn" @click="reviseClick(row)">查看</a-button>
                    </a-form-item>
                    <a-form-item>
                        <a-popconfirm
                            title="您确定要撤回这条申请吗?"
                            ok-text="确定"
                            cancel-text="取消"
                            @confirm="returnStartClick(row)"
                            @cancel="cancel"
                            >
                            <a-button v-if="linkName=='我的已办'&&row.fsfkch=='true'" class="red-btn">撤回</a-button>
                        </a-popconfirm>
                    </a-form-item>
                    <a-form-item>
                    </a-form-item>
                </a-form>
            </template>
        </commpVxeTable>
        <applicationForm ref="applicationFormRef" :linkName="linkName" :formData="formData" @success="success"></applicationForm>
    </div>
</template>
<script>
import  assessCheckApi  from './service/api.js'
import  commpVxeTable   from '@/components/commp-vxe-table/commp-vxe-table.vue'
import  applicationForm  from '../index/applicationForm.vue'
import  {queryAllYbJob,returnUpperzdyFlowJob,exportLgqsData,}  from './service/index.js'
import moment from 'moment'
export default {
    components: {
        commpVxeTable,
        applicationForm
    },
    props:{
        linkName:{
            type:String,
            default:'',
            required:false,
        },
        stepNum:{
            type:String,
            default:'',
            required:false,
        }
    },
    data() {
        return {
            moment,
            fhgsj: '',
            flgsj: '',
            time: '',
            stepNums: 0,
            reCommpVxeTable: '',
            dataTableConfig:{
                api: assessCheckApi.list,
                rowId: 'id',
                urlType: true,
                paramet:{
                    flczt: '流程结束'
                }
            },
            dataTableConfigJk: {
                api: assessCheckApi.flowJkPage,
                rowId: 'id',
                urlType: true,
                paramet: {}
            },
            dataTableConfigMe: {
                api: assessCheckApi.myJobPage,
                rowId: 'id',
                urlType: true,
                paramet: {}
            },
            dataTableConfigXiu: {
                api: assessCheckApi.Pagesjxd,
                rowId: 'id',
                urlType: true,
                paramet: {}
            },
            columnsVxe: [
                {
                    type: 'checkbox',
                    width: 60,
                    fixed: 'left'
                },{
                    title: '经办人',
                    field: 'fjbr',
                    width: 100,
                },{
                    title: '会议开始时间',
                    field: 'fhykssj',
                    width: 150,
                },{
                    title: '会议结束时间',
                    field: 'fhyjssj',
                    width: 150
                },{
                    title: '会议地点',
                    field: 'fhydd',
                    width: 200
                },{
                    title: '使用科室',
                    field: 'fsyks',
                    width: 150
                },{
                    title: '科室领导意见',
                    field: 'fzbcsyj',
                },{
                    title: '办公室意见',
                    field: 'fbgsyj',
                },{
                    title: '会议安排',
                    field: 'fhyapyj',
                },{
                    title: '操作',
                    field: 'jobid',
                    width: 150,
                    slots: {
                    // 使用插槽模板渲染
                        default: 'operation_btn',
                    },
                }
            ],
            columnsVxeMe: [
                {
                    type: 'checkbox',
                    width: 60,
                    fixed: 'left'
                },{
                    title: '经办人',
                    field: 'fjbr',
                    width: 100,
                },{
                    title: '会议开始时间',
                    field: 'fhykssj',
                    width: 150,
                },{
                    title: '会议结束时间',
                    field: 'fhyjssj',
                    width: 150
                },{
                    title: '会议地点',
                    field: 'fhydd',
                    width: 200
                },{
                    title: '使用科室',
                    field: 'fsyks',
                    width: 150
                },{
                    title: '科室领导意见',
                    field: 'fzbcsyj',
                },{
                    title: '办公室意见',
                    field: 'fbgsyj',
                },{
                    title: '会议安排',
                    field: 'fhyapyj',
                },{
                    title: '操作',
                    field: 'jobid',
                    width: 150,
                    slots: {
                    // 使用插槽模板渲染
                        default: 'operation_btn',
                    },
                }
            ],
            columnsVxeL: [
                {
                    title: '会议内容',
                    field: 'fhynr',
                },{
                    title: '会议开始时间',
                    field: 'fhykssj',
                    width: 150,
                },{
                    title: '会议结束时间',
                    field: 'fhyjssj',
                    width: 150,
                },{
                    title: '会议地点',
                    field: 'fhydd',
                    width: 200,
                },{
                    title: '使用科室',
                    field: 'fsyks',
                    width: 150,
                },{
                    title: '经办人',
                    field: 'fjbr',
                    width: 100
                },{
                    title: '发送时间',
                    field: 'ffssj',
                    width: 100
                },{
                    title: '环节名称',
                    field: 'fhjmc',
                    width: 150
                },{
                    title: '待办人',
                    field: 'fdbr',
                    width: 100
                },{
                    title: '操作',
                    field: 'jobid',
                    width: 100,
                    slots: {
                    // 使用插槽模板渲染
                        default: 'operation_btn',
                    },
                }
            ],
            formItemL: [
                {
                    label: '环节名称',
                    model: 'fhjmc',
                    placeholder: '环节名称',
                    type:'Select',
                    dictionaryType:'OA会议室管理流程'
                },{
                    label: '办理状态',
                    model: 'fblzt',
                    type:'Select',
                    options:[{
                        label:'待办',
                        value:'待办'
                    },{
                        label:'已办',
                        value:'已办'
                    }]
                },
            ],
            formItemMe: [
                {
                    label: '会议地点',
                    model: 'fhydd',
                    placeholder: '会议地点',
                    type:'Select',
                    dictionaryType:'会议室名称'
                },{
                    label: '会议开始时间',
                    model: 'fhykssj',
                    slotName:'ksTime_slot'
                },{
                    label: '会议结束时间',
                    model: 'fhyjssj',
                    slotName:'jsTime_slot'
                },
            ],
            formItem: [
                {
                    label: '经办人',
                    model: 'fjbr',
                },{
                    label: '会议地点',
                    model: 'fhydd',
                    placeholder: '会议地点',
                    type:'Select',
                    dictionaryType:'会议室名称'
                },{
                    label: '会议开始时间',
                    model: 'fhykssj',
                    slotName:'ksTime_slot'
                },{
                    label: '会议结束时间',
                    model: 'fhyjssj',
                    slotName:'jsTime_slot'
                },
            ],
            formItemL: [
                {
                    label: '环节名称',
                    model: 'fhjmc',
                    placeholder: '环节名称',
                    type:'Select',
                    dictionaryType:'OA会议室管理流程'
                },{
                    label: '办理状态',
                    model: 'fblzt',
                    type:'Select',
                    options:[{
                        label:'待办',
                        value:'待办'
                    },{
                        label:'已办',
                        value:'已办'
                    }]
                },
            ],
            idList: [],
            formData: {},
            paramet: {},
            parametMe: {},
            parametJk: {},
            parametXiu: {},

            fhykssj: '',
            fhyjssj: '',
        }
    },
    created() {
        this.paramet = JSON.parse(JSON.stringify(this.dataTableConfig.paramet))
        this.parametMe = JSON.parse(JSON.stringify(this.dataTableConfigMe.paramet))
        this.parametJk = JSON.parse(JSON.stringify(this.dataTableConfigJk.paramet))
        this.parametXiu = JSON.parse(JSON.stringify(this.dataTableConfigXiu.paramet))
    },
    methods: {
        onChange1(value, dateString){
            this.fhykssj = dateString
        },
        onChange2(value, dateString){
            this.fhyjssj = dateString
        },
        // 勾选
        checkboxChange(val){
            //console.log('已选择',val)
            this.idList = []
            if(val.length){
                val.forEach(item => {
                    this.idList.push(item.id)
                });
            }
        },
        dataConfig(){
            let data = {}
            if(this.linkName == '我的已办'){
                data = this.dataTableConfigMe
            } else if (this.linkName == '流程监控'){
                data = this.dataTableConfigJk
            } else if (this.linkName == '会议室申请记录'){
              data = this.dataTableConfig
            } else if(this.linkName == '数据修订'){
                data = this.dataTableConfigXiu
            }
            return data
        },
        columns(){
            let data = []
            if(this.linkName == '我的已办'){
                data = this.columnsVxeMe
            } else if (this.linkName == '流程监控'){
                data = this.columnsVxeL
            } else if (this.linkName == '会议室申请记录'){
                data = this.columnsVxe
            } else if(this.linkName == '数据修订'){
                data = this.columnsVxeMe
            }
            return data
        },
        item(){
            let data = []
            if(this.linkName == '我的已办'){
                data = this.formItemMe
            } else if (this.linkName == '流程监控'){
                data = this.formItemL
            } else if (this.linkName == '会议室申请记录'){
                data = this.formItem
            } else if(this.linkName == '数据修订'){
                data = this.formItemMe
            }
            return data
        },
        // 搜索
        searchEvent(){
            this.dataTableConfig.paramet = {
                ...this.dataTableConfig.paramet,
            }
            //console.log(this.dataTableConfig.paramet)
        },
        // 重置
        resetEvent(){
            this.dataTableConfig.paramet = {
                ...this.dataTableConfig.paramet,
            }
        },
        // 申请确认
        addClick(){
            this.$nextTick(_ => {
                this.$refs.applicationFormRef.applicationFormVisible = true
            })
        },
        // 点击办理
        reviseClick(row){
            //console.log('办理',row)
            this.formData = {
                ...row
            }
            let jobid = row.jobid
            // queryJobByJobId({jobid:jobid}).then(res => {
            //     //console.log(res)
            // })
            this.formData.id = row.oaid
            this.$nextTick(_ => {
                this.$refs.applicationFormRef.applicationFormVisible = true
            })
        },
        // 撤回申请
        returnStartClick(row){
            queryAllYbJob({jobid:row.jobid}).then(res => {
                let list = res.result
                list.forEach(item => {
                    if(item.fhjmc == '申请确认'){
                        this.returnFuntion(row.jobid,item.id)
                    }
                })
            })
        },
        returnFuntion(jobid,ids){
            let data = {
                jobid: jobid,
                opinion: '撤回申请',
                shjid: ids,
                smgflag: '',
                smsContent: '',
            }
            returnUpperzdyFlowJob(data).then(res => {
                if(res.code == 200){
                    that.$message.success(res.message)
                    that.reCommpVxeTable = Date.now()
                } else {
                    that.$message.warning(res.message)
                }
            })
        },
        //
        cancel(e) {
            //console.log(e);
        },
        // 弹窗提交成功
        success(){
            // 刷新表格 清空id数组
            this.$refs.administrativeOffice.resetEvent()
            this.idList = []
        }
    },
}
</script>
<style>
@import url('../../css/oaClass.css');
</style>
